package admin;

import java.util.List;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;



public class Admin extends Model<Admin> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 300L;
	public static final String Admin_Session = "admin_session";
	public static final Admin dao = new Admin();
	
	/**
	 * 登录验证
	 * @param uname
	 * @param upass
	 * @return
	 */
	public Admin login(String uname,String upass){
		Admin u = dao.findFirst("select * from admin where account = ? and passwd = ?",uname,upass);
		return u;
	}
	
	/**
	 * 根据管理查询所有子管理员
	 * @return
	 */
	public List<Record> findByInfo(int adminid){
		try{
			String sql = "select a.id,a.account,a.phone,a.name,r1.name as rname,a.createdate ";
			sql += "from admin a left join role r1 on r1.id=a.roleId where a.adminid='"+adminid+"'";
			sql += "order by a.createdate desc";
			return Db.find(sql);
		}catch (Exception e) {
			return null;
		}
	}
	
	
}
